import { defineStore } from 'pinia'
import { ref } from 'vue'

const useConsultStore = defineStore(
	'consult',
	() => {
		const illnessInfo = ref({
			illnessDesc: '', // 病情描述
			illnessTime: 1, // 患病时长
			consultFlag: 0, // 是否就诊过 0-未就诊过, 1-就诊过
			pictures: [], // 病情相关图片[ { id, url } ]
		})
		const type = ref('0')
		const setType = (data) => {
			type.value = data
		}
		const illnessType = ref('')
		const setillnessType = (data) => {
			illnessType.value = data
		}
		const depId = ref('')
		const setdepId = (data) => {
			depId.value = data
		}

		const setIllnessInfo = (data) => {
			Object.assign(illnessInfo.value, data) // 浅拷贝 替换
		}
		const clear = () => {
			illnessInfo.value = {
				illnessDesc: '', // 病情描述
				illnessTime: 1, // 患病时长
				consultFlag: 0, // 是否就诊过 0-未就诊过, 1-就诊过
				pictures: [], // 病情相关图片[ { id, url } ]
			}
		}

		// 患者id
		const patientId = ref('')
		const setPatientId = (newPatientId) => (patientId.value = newPatientId)

		return {
			illnessInfo,
			setIllnessInfo,
			type,
			setType,
			illnessType,
			setillnessType,
			depId,
			setdepId,
			patientId,
			setPatientId,
		}
	},
	{
		persist: true,
	}
)

export default useConsultStore
